package com.s3u4.demo.zookeeper.base;

import com.s3u4.demo.zookeeper.ZkConfig;
import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.List;

/**
 * 删除组
 * Created by Captain on 01/08/2017.
 */
public class DeleteGroup extends ConnectionWatcher {

    public void delete(String path){
        System.out.println("delete Group : " + path);
        List<String> children;
        try {
            children = zooKeeper.getChildren(path,false);
            for (String child : children){
                System.out.println("delete Group : " + path + "/" + child);
                zooKeeper.delete(path + "/" + child, -1);
            }
            zooKeeper.delete(path,-1);
        } catch (KeeperException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        DeleteGroup deleteGroup = new DeleteGroup();
        deleteGroup.connect(ZkConfig.ZK_HOST);
        deleteGroup.delete("/demo-zookeeper");
        deleteGroup.close();
    }

}
